package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.Prov;
import com.sevattal.service.leaves.service.ProvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 供应商表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "供应商管理")
@RestController
@RequestMapping("/admin/leaves/prov")
public class ProvController {

    @Autowired
    private ProvService provService;

    @ApiOperation("新建供应商")
    @PostMapping("createProv")
    public R createProv(@ApiParam(value = "供应商对象",required = true) @RequestBody Prov prov){
        boolean result = provService.createProv(prov);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改供应商")
    @PutMapping("updateProv")
    public R updateProv(@ApiParam(value = "供应商对象",required = true) @RequestBody Prov prov) {
        boolean result = provService.updateProv(prov);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除供应商")
    @DeleteMapping("deleteProv/{id}")
    public R deleteProv(@ApiParam(value = "供应商id",required = true) @PathVariable String id) {
        boolean result = provService.deleteProv(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }


    @ApiOperation("获取供应商信息")
    @PostMapping("getProvList")
    public R getProvList(@ApiParam(value = "供应商对象",required =  true)  @RequestBody Prov prov){
        List<Prov> result = provService.getProvList(prov);
        return R.ok().data("provList",result);
    }

}

